Method for efficient and reliable computation of results for mathematical functions

ABSTRACT

A method is provided for efficient computation of reliable results for mathematical functions. The method may include an interface, a control module, and an error module. The interface receives a mathematical function call. The call includes a plurality of arguments for which a range of computable results for the mathematical function varies with respect to the values for the arguments. The control module determines whether executing the mathematical function using the plurality of arguments will produce a result within the range of computable results. The error module aborts the mathematical function call prior to initiating execution of the mathematical function in response to determining that the values for the plurality of arguments produce a result outside the range of computable results.

CROSS-REFERENCES TO RELATED APPLICATIONS

This application is a continuation of and claims priority to U.S. patentapplication Ser. No. 10/862,559 entitled “Apparatus and System forEfficient and Reliable Computation of Results for MathematicalFunctions” and filed on Jun. 7, 2004 for John Robert Ehrman, which isincorporated herein by reference.

BACKGROUND OF THE INVENTION

1. Field of the Invention

The invention relates to software for implementing mathematicalfunctions. Specifically, the invention relates to methods for efficientand reliable computation of results for mathematical functions.

2. Description of the Related Art

Generally, processing systems such as computers and calculators arecapable of evaluating a set of general purpose mathematical functions,also referred to herein as math functions. Certain math functions areexecuted hundreds or thousands of times to perform what appear to a userto be simple operations, such as simple animation. The softwarelibraries that implement the math functions are consequently written forvery fast execution using a highly optimized form of assembly languageor machine code. Generally, these math functions perform well for alarge set of values that can be provided as arguments to the mathfunction.

Math functions are considered to provide results within number setsbounded by negative infinity and positive infinity. Conventionalcomputers, however, have natural limits on the maximum value, minimumvalue, and type of value that can be represented in the computer.Typically, these limits depend on the hardware and software architectureof the processing system that evaluates the math function. Values thatfall outside of these limits are referred to herein as unrepresentablevalues or incomputable results. Similarly, values that fall within theselimits are referred to as computable results or representable values.Incomputable results are those for which a valid mathematical resultexists, but the result can not be represented due to natural limits ofthe processing system.

To account for natural limits on results for math functions,conventional systems often check an argument for invalid values. Suchinvalid values can be of several types, including those for which theresult for the math function is undefined (such as division by zero).Certain math functions check in advance for incomputable results. Forexample, on a computer using the IBM hexadecimal floating point datarepresentation, a routine that evaluates the exponential function exp(X)for a floating point argument X can check that the value of X does notexceed 174.673. If so, an error condition is signaled for anunrepresentable, invalid result. Other functions of a single argumentsuch as exp(x), sinh(x), cosh(x), tan(x), arcsin(x), gamma(x), and thelike typically check the argument value against one or two limit values(such as upper and lower bounds) to identify unrepresentable values.

Conventional math functions, however, typically fail to perform suchchecking for a computable result when the function involves a pluralityof arguments. Conventionally, the overhead in determining whether theargument values will provide a computable result causes an unacceptabledelay. Consequently, conventional math functions favor speed overreliability in evaluating functions that accept a plurality ofarguments. The math functions presume that for the argument valuesprovided the math function will return a representable result.Accordingly, the math function is evaluated using the argument values.The math function evaluation can consume considerable memory andprocessing resources. If the result of the math functions turns out tobe unrepresentable, these resources are wasted.

Consequently, such function argument values are permitted to evaluateuntil the processing system detects that the result being computed isunrepresentable or noncomputable. Generally, a noncomputable result oran unrepresentable result is one that is a mathematically undefinedresult for the function, larger than the processing system is designedto represent, smaller than the processing system is designed torepresent, or includes an imaginary portion such as with complex numberswhen a real (non-complex) result is required.

FIG. 1 illustrates a conceptual representation 100 of a function f(x,y)that accepts a plurality of arguments (x,y) and maps values in a domain(x,y) 102 to a mathematical range f(x,y) 104 defined for the functionf(x,y). The domain 102 and range 104 each comprises a number set of thesame or different type. For example, the domain 102 may include wholenumbers and the range 104 may include real numbers such as a decimal orother non-integer number.

The function f(x,y) 106 maps, or translates, a given x and a given yfrom the domain 102 to a proper result in the range 104. For example,suppose the domain 102 comprises whole numbers (integers as representedin the computer) and the function 106 is the mathematical power functionf(x,y)=x̂y. For most x and y values chosen in the domain 102, thefunction returns a valid computable result 108. If x=2 and y=3, f(x,y)returns the result 8. For certain values of x and y, the mathematicalfunction may be undefined. So, if x=0 and y=0, the function 106, x̂y,maps to a mathematically undefined result 110.

Other combinations of arguments x and y produce a result 112 that iseither too large, or too small for the processing system evaluating thefunction 106 to represented. If the result or an intermediate result istoo large, the condition is referred to as overflow. If the result or anintermediate result is too small, the condition is referred to asunderflow.

Because the result is unrepresentable, the result is consideredincomputable for the particular processing system. For example, supposethe processing system represents numbers as integers in a memorylocation having thirty-one data bits and one sign bit. Using the samefunction 106, x̂y, if x=2 and y=31 the result 112 is larger than thelargest positive integer that can be stored in a result memory locationof the processing system.

FIG. 1 illustrates that this result 112 is mathematically valid, iswithin the mathematical range 104, but in this case is too large for thecomputer to represent using its standard hardware and architecture. Sucha result 112 is considered outside the computable range 114 for thefunction 106. The computable range 114 represents a range of allcomputable results for a given function 106.

Results 112 outside of the computable range 114, includingmathematically undefined results 110, are considered error conditions.Generally, the math function will signal this error condition. However,the math function typically does not identify the error condition untillarge amounts of time, memory, and processing power are expended.

Unfortunately, conventional math functions do not determine whether thegiven arguments will produce a computable result 108. One reason forthis is the variation between arguments that can dramatically alterwhether the result is within the computable range 114. For example, agiven x and y value may produce a computable result 108. But changingone argument or the other can produce an incomputable result 110, 112.Keeping the same x value and using y′ produces an undefined result 110.Keeping the same y and using x′ produces incomputable result 112 due tooverflow or underflow.

The interrelationships between the arguments and the function 106 andthe affect of these relationships on the result falling within the rangeof computable results 114 make detecting such error conditions forvalues of a plurality of arguments very difficult. The range ofcomputable results 114 varies depending on which values are provided forthe arguments. Furthermore, the range of computable results 114 isshifted based on the value of a first argument in relation to the valueof a second argument. Conventional math functions avoid such testing ofarguments for a particular function because the overhead (whichintroduces a delay in function execution) in conducting such tests isexpected to outweigh the benefit of preventing wasted computingresources.

From the foregoing discussion, it should be apparent that a need existsfor a method for efficient and reliable computation of results formathematical functions. Beneficially, such method would operateaccurately and very quickly in testing a plurality of math functionarguments to determine whether present argument values produce a resultwithin the range of computable results. Beneficially, the method wouldincur minimal overhead in testing the arguments. In addition, the methodwould prevent wasting computing resources evaluating a function forwhich the plurality of arguments would produce an incomputable result.

SUMMARY OF THE INVENTION

The various embodiments of the present invention have been developed inresponse to the present state of the art, and in particular, in responseto the problems and needs in the art that have not yet been met forefficient and reliable computation of results for mathematicalfunctions. Accordingly, the various embodiments have been developed toprovide a method for efficient and reliable computation of results formathematical functions that overcomes many or all of the above-discussedshortcomings in the art.

An apparatus according to one embodiment includes an interface, acontrol module, and an error module. The interface receives amathematical function call that includes a plurality of arguments forwhich a range of computable results for the mathematical function of thefunction call varies with respect to the values for the arguments. Thecontrol module determines whether executing the mathematical functionusing the plurality of arguments will produce a result within the rangeof computable results.

Preferably, the control module makes this determination by comparing oneargument value with boundary values for the other argument values. Theboundary values are predefined values that for a given first argumentvalue, if the second argument value crosses the boundary (is greaterthan or less than, as appropriate), the result of the function will beoutside the range of computable results. If the control moduledetermines that the values for the plurality of arguments produce aresult outside the range of computable results, the error module abortsthe mathematical function call prior to initiating execution of themathematical function.

Preferably, one function argument is the index, lookup, or key value.Using the index value for the one function argument, a one or moreboundary values corresponding to each additional function argument maybe referenced to determine whether argument values for those additionalfunction arguments cross an associated boundary value. Each functionargument that is not the index value may have a boundary value for anupper bound and a boundary value for a lower bound.

In certain embodiments, the control module may include a reader module,a lookup module, and a comparison module. The reader module reads afirst value associated with a first argument of the mathematicalfunction and a second value associated with a second argument. Thelookup module retrieves a boundary value from a repository of predefinedboundary values defined for the mathematical function over a domain ofthe first argument, the boundary value retrieved using the first value.The comparison module determines whether the second value satisfies theboundary value.

Whether the second value satisfies the boundary value may depend on thetype of boundary value. In certain embodiments, the comparison moduleuses a maximum boundary value. If the second value exceeds the maximumboundary value, the current set of function values will produce a resultoutside the range of computable results.

Similarly, in one embodiment, the comparison module uses a minimumboundary value. If the second value is less than the maximum boundaryvalue, the current set of function values will produce a result outsidethe range of computable results. Still other embodiments may use both aminimum boundary and a maximum boundary. In these embodiments, toproduce a computable result (a result within the computable range), thesecond value should be between the minimum boundary and the maximumboundary. By quickly testing the function arguments against predefinedboundary values, certain embodiments are capable of rapidly determiningwhether evaluation of the function should be aborted to preservecomputing resources. The overhead incurred to perform this simplecomparison with the boundary values is minimal in terms of space andtime required.

In another embodiment, the repository of predefined boundary values maybe configured to optimally provide accurate tests of arguments andbalance the time and space required to access and maintain therepository. In certain embodiment, the computable range may depend onvarious machine specific factors such as the size of memory structuresused to store atomic values during math function execution, the waynumbers are represented in the storage of atomic values, and the numerictypes accepted as valid arguments for the function. For example, therange of computable results can change dramatically based on whether thefunction operates on integer types, floating point types, or acombination of these. Those of skill in the art will recognize variousimplementation tradeoffs in designing the size and configuration of therepository of predefined boundary values.

A method for efficient and reliable computation of results formathematical functions is also presented. In one embodiment, the methodincludes receiving a mathematical function call, the call comprising aplurality of arguments for which a range of computable results for themathematical function of the function call varies with respect to thevalues for the arguments. A determination is then made whether executingthe mathematical function using the plurality of arguments will producea result within the range of computable results. Lastly, the methodaborts the mathematical function call prior to initiating execution ofthe mathematical function in response to determining that the values forthe plurality of arguments produce a result outside the range ofcomputable results.

In certain embodiments, the method reads a first value associated with afirst argument of the mathematical function and a second valueassociated with a second argument. Next, a boundary value is retrievedfrom a repository of predefined boundary values defined for themathematical function over a domain of the first argument. Of course anyargument for the mathematical function may serve as the first argument.

In one embodiment, the boundary value is retrieved using the firstvalue. Then, a determination is made whether the second value satisfiesthe boundary value condition or conditions. If so, computing the resultfor the mathematical function using the first and second values willproduce a result within the range of computable results.

Various embodiments for efficient and reliable computation of resultsfor mathematical functions may be arranged as a system andmachine-readable instructions that comprise substantially the samefunctionality as the components and steps described above in relation tothe apparatus and method. The one embodiment provides a fast test formath functions with a plurality of arguments. The test imposes minimaloverhead on computations for values that produce results in the range ofcomputable results. Beneficially, one embodiment prevents evaluation ofmath functions for arguments that will produce a result outside therange of computable results. In this manner, math functions areoptimized and fewer computing resources are wasted. The features andadvantages of different embodiments will become more fully apparent fromthe following description and appended claims, or may be learned by thepractice of embodiments of the invention as set forth hereinafter.

BRIEF DESCRIPTION OF THE DRAWINGS

In order that the advantages of the different embodiments of theinvention will be readily understood, a more particular description ofthe embodiments briefly described above will be rendered by reference tospecific embodiments that are illustrated in the appended drawings.Understanding that these drawings depict only typical embodiments of theinvention and are not therefore to be considered to be limiting of itsscope, the embodiments will be described and explained with additionalspecificity and detail through the use of the accompanying drawings, inwhich:

FIG. 1 is a graph diagram illustrating logically how functions may mapargument values in a domain to a mathematical or computable range;

FIG. 2 is a schematic block diagram illustrating one embodiment of asystem for efficient and reliable computation of results formathematical functions;

FIG. 3 is a schematic block diagram illustrating one embodiment of anapparatus for efficient and reliable computation of results formathematical functions;

FIG. 4 is a schematic flow chart diagram illustrating one embodiment ofa method for efficient and reliable computation of results formathematical functions;

FIG. 5 is a schematic flow chart diagram illustrating more detail of oneembodiment of a method for efficient and reliable computation of resultsfor mathematical functions;

FIG. 6 is a schematic flow chart diagram illustrating one embodiment ofa method for efficient and reliable computation of results formathematical functions;

FIG. 7A is a table diagram illustrating an example of a data structurefor a repository of boundary values;

FIG. 7B is a schematic block diagram illustrating one example of a datastructure suitable for use in efficient and reliable computation ofresults for mathematical functions;

FIG. 7C is a table diagram illustrating an example of a data structurefor a repository of boundary values according to another embodiment; and

FIG. 8 is a graph diagram illustrating how variation in values ofarguments for multi-argument functions affect the range of computableresults.

DETAILED DESCRIPTION OF THE INVENTION

It will be readily understood that the components of embodiments of thepresent invention, as generally described and illustrated in the Figuresherein, may be arranged and designed in a wide variety of differentconfigurations. Thus, the following more detailed description of theembodiments of the method of the present invention, as presented in theFigures, is not intended to limit the scope of the invention, asclaimed, but is merely representative of selected embodiments of theinvention.

Many of the functional units described in this specification have beenlabeled as modules, in order to more particularly emphasize theirimplementation independence. For example, a module may be implemented asa hardware circuit comprising custom VLSI circuits or gate arrays,off-the-shelf semiconductors such as logic chips, transistors, or otherdiscrete components. A module may also be implemented in programmablehardware devices such as field programmable gate arrays, programmablearray logic, programmable logic devices or the like.

Modules may also be implemented in software for execution by varioustypes of processors. An identified module of executable code may, forinstance, comprise one or more physical or logical blocks of computerinstructions which may, for instance, be organized as an object,procedure, function, or other construct. Nevertheless, the executablesof an identified module need not be physically located together, but maycomprise disparate instructions stored in different locations which,when joined logically together, comprise the module and achieve thestated purpose for the module.

Indeed, a module of executable code could be a single instruction, ormany instructions, and may even be distributed over several differentcode segments, among different programs, and across several memorydevices. Similarly, operational data may be identified and illustratedherein within modules, and may be embodied in any suitable form andorganized within any suitable type of data structure. The operationaldata may be collected as a single data set, or may be distributed overdifferent locations including over different storage devices, and mayexist, at least partially, merely as electronic signals on a system ornetwork.

Reference throughout this specification to “a select embodiment,” “oneembodiment,” or “an embodiment” means that a particular feature,structure, or characteristic described in connection with the embodimentis included in at least one embodiment of the present invention. Thus,appearances of the phrases “a select embodiment,” “in one embodiment,”or “in an embodiment” in various places throughout this specificationare not necessarily all referring to the same embodiment.

Furthermore, the described features, structures, or characteristics maybe combined in any suitable manner in one or more embodiments. In thefollowing description, numerous specific details are provided, such asexamples of programming, software modules, user selections, userinterfaces, network transactions, database queries, database structures,hardware modules, hardware circuits, hardware chips, etc., to provide athorough understanding of embodiments of the invention. One skilled inthe relevant art will recognize, however, that the embodiments of theinvention can be practiced without one or more of the specific details,or with other methods, components, materials, etc. In other instances,well-known structures, materials, or operations are not shown ordescribed in detail to avoid obscuring aspects of the variousembodiments.

The illustrated embodiments of the invention will be best understood byreference to the drawings, wherein like parts are designated by likenumerals throughout. The following description is intended only by wayof example, and simply illustrates certain selected embodiments ofdevices, systems, and processes that are consistent with the inventionas claimed herein.

FIG. 2 illustrates a logical block diagram of a system 200 suitable forefficient and reliable computation of results for mathematicalfunctions. The system 200 may include a memory 202, a processor 204, andan Input/Output (I/O) module 206. Those of skill in the art willrecognize that the memory 202, processor 204, and Input/Output (I/O)module 206 are operably connected using hardware such as a communicationbus. Alternatively, the memory 202, a processor 204, and Input/Output(I/O) module 206 may be distributed among a number of processing systemsand communicate using a network interconnect.

The memory 202 may comprise a non-volatile memory such as a hard diskdrive, Compact Disk Read Only Memory CDROM drive, a read-only memorydevice, or a random access volatile memory (RAM). Alternatively, thememory 202 may comprise a combination of ROM and RAM. For example,certain data may be stored in ROM that serves as a cache. In certainembodiments, the memory 202 is on a chip that implements the processor204.

The processor 204 comprises any processor suitable for evaluating mathfunctions. The processor 204 may comprise a general purpose processorsuch as a Central Processing Unit (CPU) of a computer or a specialpurpose processor of an Application Specific Integrated Circuit (ASIC).

The I/O module 206 may receive inputs from a user or another device.Similarly, the I/O module 206 may send output to one or more outputdevices such as a monitor or a printer. In one embodiment, the I/Omodule communicates results of math functions to a user and/or errormessages associated with error conditions for the math functions.

Preferably, the system 200 includes a function range test module 208 anda set of boundary values 210. Preferably, the processor 204 executes thefunction range test module 208 prior to evaluating object code toperform a math function 212.

In one embodiment, the processor 204 transmits substantially all mathfunction calls to the function range test module 208. If the functionrange test module 208 is configured to test arguments for the particularfunction call, the function range test module 208 returns a value to theprocessor 204 indicating whether proceeding with evaluation of thefunction call will produce a computable result. If the function rangetest module 208 is not configured to test the particular function,control is returned to the processor 204 which then evaluates thefunction 212 with the given arguments.

Alternatively, the function range test module 208 is integrated into oneor more select math functions 212. For example, math functions 212 thatuse a plurality of arguments or complex numbers for one or morearguments may include the function range test module 208. Examples ofmath functions 212 that may utilize the function range test module 208include a power function (x̂y), a Bessel function, a Jacobi function. Inaddition, functions for computing well-known constants may also use thefunction range test module 208. For example, a function to compute C,C(n,m), which computes the number of combinations of n items taken m ata time. In addition, a function to compute the “Stirling Numbers,”S(n,x) may also use the function range test module 208.

The function range test module 208 determines whether the values forfunction calls that include a plurality of arguments or at least onecomplex number argument will produce a result within the range ofcomputable results for the particular function 212. The function rangetest module 208 references the set of boundary values 210 in order tomake a rapid determination based on the particular function call and thespecific values provided for the function arguments.

The set of boundary values 210 may include one or more subsets ofboundary values specific to a particular function. Alternatively, thememory 202 comprises a different set of boundary values 210 for eachfunction 212 supported by one embodiment. The sets of boundary values210 are preferably structured such that for a given value or index oneor more corresponding boundary values can be referenced.

In one example, the system 200 is initiated when a software programissues a mathematical function call. In one embodiment, the processor204 or a math co-processor for the processor directs the function calland the argument values for the call to the function range test module208. The function range test module 208 determines whether the functionargument values will produce a result within the range of computableresults for the particular function. Details of this determination areexplained below.

If the result is computable, the processor 204 then evaluates the mathfunction 212. If not, the processor 204 communicates the error conditionto the application 214 or directly to a user using the I/O module 206.In this manner, the system 200 prevents wasted computing resourcesattempting to compute a result which is incomputable. Furthermore, thefunction range test module 208 performs the test so quickly thatoverhead in performing test is minimal. Consequently, the benefit inperforming the test provides fast reliable results that outweighs therisk of wasting computing resources or continuing computations with anerroneous result.

FIG. 3 illustrates an apparatus 300 according to one embodiment forefficient and reliable computation of results for mathematicalfunctions. In one embodiment, the apparatus 300 comprises softwaremodules that implement the function range test 208 of FIG. 2. Of course,the apparatus 300 may be implemented as hardware or software.

The apparatus 300 includes an interface 302, a control module 304 and anerror module 306. The interface 302, control module 304, and errormodule 306 cooperate to determine whether the function arguments willproduce a computable result 108 (See FIG. 1). The interface 302, controlmodule 304, and error module 306 preferably communicate usingconventional software techniques such as function calls, pointers, andthe like.

The interface module 302 receives a mathematical function call. In oneembodiment, the interface module 302 comprises an ApplicationProgramming Interface (API) that facilitates use of the servicesprovided by the function range test module 208 to various softwaremodules. The function call identifies the function that is to beevaluated as well as the argument values for the function. Preferably,the function call is one that includes a plurality of arguments forwhich the range of computable results 114 (See FIG. 1) varies withrespect to the values of the arguments. This means that given a firstargument value, the result produced for a given second argument valuemay or may not fall within the range of computable results 114.

Of course function calls involving more than two arguments may also beevaluated in the same manner as described below. Furthermore, functioncalls having a single argument that comprises a complex number, z, suchthat z=x+iy (where i=square root of −1), can also be used with thefunction range test module 208. Examples of such functions includetrigonometric functions of a complex variable including sin(z), cos(z),tan(z), sinh(z), cosh(z), tanh(z), and others.

The interface module 302 communicates an identifier of the function andthe argument values to the control module 304. The control module 304determines whether evaluation or execution of the math function usingthe provided argument values will produce a result within the range ofcomputable results 114. Preferably, the control module 304 makes thisdetermination by examining each of the argument values provided anddetermining whether each argument value is within certain limits,referred to herein as boundaries. The boundaries for each argument valuechange based on the other argument values.

Computing these boundaries may incur a prohibitive delay. Consequently,predefined boundaries may be included that are referenced by the controlmodule 304 to make the determination. If all the argument values fallwithin the boundaries, the result is within the range of computableresults.

The boundaries are marked by one or more boundary values 210. Typically,each set of boundary values 210 is directly related to a particularfunction. While the variability of a second argument affects the rangeof computable results 114, a boundary value for the second value isknown and predefined. If the second value crosses the boundary value (isgreater than or less than the boundary value, as appropriate) the resultis known to be outside the range of computable results 114.

To facilitate examination of boundary values in relation to argumentvalues, the control module 304 may include a reader module 308, a lookupmodule 310 and a comparison module 312. The reader module 308 reads afirst value associated with a first argument of the mathematicalfunction and a second value associated with a second argument. One ofthe arguments is used as an identifier for referencing the boundaryvalues 210. In other words, the argument is a key or index into a datastructure that stores the boundary values.

The lookup module 310 uses the value for the key or index argument, thefirst value, to retrieve a boundary value from a repository 314 ofpredefined boundary values 210. The repository 314 may comprisesubstantially any data structure capable of returning one or moreboundary values 210 in response to a specific index or key value. Forexample, the repository 314 may comprise a list of key-value pairs.Alternatively, the repository 314 may comprise a hash table or othersimilar data structure.

In one embodiment, the repository 314 comprises a table of data in arow-column format. The table may be referred to as a lookup tablebecause the table is typically predefined and used just for referenceand not for changing and storing disparate data. Each row in the tablemay include one or more boundary values specific to a particularargument value. The first value read by the reader module 308 may serveas an index in locating a row in the table.

Preferably, the set of boundary values 210 includes at least oneboundary value for each first value within a domain of the firstargument. In building the predefined set of boundary values 210, certainvalues for the first argument will reach a natural limit, an upperboundary and a lower boundary, for which a higher or lower value of thefirst argument will produce an incomputable result for the function. Thevalues for the first argument between the lower boundary and the upperboundary comprise the domain of the first argument. Consequently,boundaries for the first argument may be checked by the presence orabsence of a boundary value for a given first value.

Alternatively, the domain of the first argument may comprise an infinitenumber of possible values. Consequently, the set of boundary values 210may comprise a reasonable subset of the domain of the first argument. Inthis manner, the size of the set of boundary values 210 is kept withindesign parameters for the repository 314. In one embodiment, firstvalues that do not include a corresponding boundary value in the set ofboundary values 210 may automatically cause the function range testmodule 208 to permit evaluation of the function. In another embodiment,these first values may automatically cause the function range testmodule 208 to signal an error condition. The behavior implementeddepends largely on the makeup and design of the set of boundary values210.

The lookup module 310 provides the one or more retrieved boundary valuesto the comparison module 312. The comparison module compares the secondvalue to the one or more retrieved boundary values. Depending on thetype of boundary value(s), the comparison module 312 determines whetherthe second value satisfies the boundary values.

Typically, boundary values are of two types, a maximum boundary valueand a minimum boundary value. If the boundary value is a maximumboundary value, second values greater than the maximum boundary valuefail to satisfy the boundary value. If the boundary value is a minimumboundary value, second values less than the minimum boundary value failto satisfy the boundary value. If both a maximum boundary value and aminimum boundary value are provided, the second value should be betweenthe maximum boundary value and the minimum boundary value to satisfy theboundary value test.

If the second value satisfies the boundary value, the comparison module312 signals that based on the first value and second value the functionwill provide a result 108 (See FIG. 1) within the range of computableresults 114. If not, the comparison module 312 signals an errorcondition. If the comparison module 312 determines that the functionwill provide a computable result 108 and more than two arguments exist,the reader 308, lookup module 310, and comparison module 312 cooperateto compare each additional argument value to corresponding boundaryvalues in the set of boundary values 210. Preferably, the same firstvalue is used as the index to retrieve the proper boundary values fromthe set of boundary values 210. In certain embodiments, this process isrepeated until all argument values have been compared with acorresponding boundary value in the repository 314. In one embodiment, asubsequent set of boundary values for a next argument may depend on thevalue of the second argument being properly validated.

If an error condition is signaled, the comparison module 312communicates with the error module 306. Typically, an error conditioncomprises any combination of argument values for the function that willproduce a result 110, 112 (See FIG. 1) outside the range of computableresults 114. As mentioned above, error conditions may include overflowerrors, underflow errors, and mathematically undefined results for thegiven set of argument values. The error module 306 aborts themathematical function call prior to a processor 204 (See FIG. 2)initiating execution of the mathematical function 212. In oneembodiment, based on a return value from the function range test module208 signaling an error condition, the processor 204 may then notevaluate the math function 212. Instead, the processor 204 mayfacilitate communication between the error module 306 and the I/O module206 such that an error message is presented. Alternatively, a returncode signaling an error condition may be returned to the function orobject code that initiated the function call.

Advantageously, the apparatus 300 provides a fast, efficient, functionrange test module 208 for determining whether a given function callhaving a plurality of arguments will produce a computable result 108.The predefined boundary values in the repository 314 provide quickaccess for high speed comparisons to rapidly determine whether executionof the function call should continue and will produce a computableresult. In addition, the comparison quickly determines whether executingthe function with the given argument values would waste computingresources because of the incomputable results 110, 112.

FIG. 4 illustrates a schematic flow chart diagram illustrating oneembodiment of a method 400 for efficient and reliable computation ofresults for mathematical functions. The method 400 begins 402 once afunction call is issued for a math function that includes either acomplex number argument or a plurality of arguments. First, theinterface module 302 (See FIG. 3) receives 404 the mathematical functioncall. Next, the control module 304 determines 406 whether a resultcomputed for the function call with the given argument values will bewithin the range of computable results 114 (See FIG. 1). If so, theprocessor 204 executes the math function 212 to compute the result 108.

If not, the error module 306 signals 410 an error condition. The errorcondition may be communicated to the processor 204, and I/O module 206,a software module that initiated the math function call, or the like.Preferably, the error condition signaled 410 by the error module 306prevents execution of the math function 212 before computing resourcesare wasted. Once an error condition is signaled or the processor 204begins evaluating the math function 212, the method 400 ends 412.

FIG. 5 illustrates a schematic flow chart diagram illustrating oneembodiment of a method 500 for determining whether function argumentvalues that interrelate to define the range of computable results 114will produce a result 110, 112 outside the range of computable results114. Initially, a read module 308 reads 502 a first value associatedwith a first argument for the math function and a second valueassociated with a second argument. Preferably, the first value andsecond value are read from a storage location in memory 202.Alternatively, the first value and second value are fetched from abuffer or other data structure temporarily storing the values associatedwith the function arguments.

In one embodiment, the control module 304 is configured to conductspecial checks for certain argument values that produce well-known andwell-defined results. Certain arguments may produce a particular resultregardless of the values for the other arguments or may lead to awell-known undefined result for the function. Consequently, the controlmodule 304 may perform these special tests prior to continuing themethod 500.

For example, suppose the function is x̂y. The x value is 0 and the yvalue is 0. The result is mathematically undefined. The control modulemay test the x and y values for 0. If x and y are 0, the control module304 may cause the error module to signal the error condition, withoutperforming any more of the steps of method 500 described below.

In certain embodiments, where a function has more than two arguments theread module 308 may read all the arguments and store the correspondingvalues in temporary storage locations in memory 202. In anotherembodiment, for functions that accept one or more complex numbers, theread module 308 may divide a complex number value into its real part andimaginary part. Each part may then be stored in particular temporarystorage locations. Of course a math function may comprise argumentshaving a homogeneous or heterogeneous set of numeric types includinginteger, floating point, and complex.

Next, a lookup module 310 retrieves 504 at least one boundary value.Preferably, the boundary value is located using the first value as anidentifier, a key or index into a set of boundary values 210. In certainembodiments, the first value is used directly for the index. In otherembodiments, the first value is used as a basis for computing the index.For example, suppose the indexes are whole numbers. If the first valueis a decimal or non-integer number, the first value may be roundedaccording to various rounding techniques to produce a whole numbercorresponding to the proper index.

Preferably, the set of boundary values 210 are organized in a table withthe boundary values serving as columns and the rows corresponding tovalues within the domain of the first argument. The rows indexed by thevalues of the first argument contain boundary values that will allowevaluation of a computable result 108. Consequently, if the lookupmodule 310 fails to find a row in the table corresponding to the indexderived from the first value, the first value may be considered a valuethat will produce a result for the function outside the range ofcomputable results 114. Accordingly, execution of the function call isaborted.

Next, the comparison module 312 determines 506 whether second valuesatisfies the boundary value. Satisfaction of the boundary value meansthe second value and the first value together will produce a result forthe function within the range of computable results 114.

If the boundary value is satisfied, the control module 304 may determine508 whether the function includes more than two arguments. If so, themethod 500 returns to step 502 where a value for the next argument isread. In certain embodiments, a boundary value is retrieved 504 for thevalue of the next argument using the first value. Alternatively, a rowof the table may include a plurality of boundary values that eachcorrespond to a different argument such that the row can be retrieved504 just once. Alternatively, a row of the table may include an index orpointer to another row of the table depending on the values ofpreviously validated arguments.

If no more function arguments exist, the processor 204 computes 510 theresult for the function. If a second or subsequent value fails tosatisfy its corresponding boundary value(s), the error module 306signals 512 an error condition as described above in relation to FIG. 3.

FIG. 6 illustrates a schematic flow chart diagram illustrating oneembodiment of a method 600 for determining whether function argumentvalues that interrelate to define the range of computable results 114will produce a result 110, 112 outside the range of computable results114. The method 600 is very similar to the method 500 described above.However, depending on the function and the type of argument values beingused, each function argument value may have an upper bound and a lowerbound that affects the range of computable results.

As in method 500, a read module 308 reads 602 a first value and a secondvalue. Also as in method 500, a lookup module 310 retrieves 604 oneboundary value. This boundary value may comprise a maximum boundaryvalue. Next, the lookup module 310 may retrieve 606 a minimum boundaryvalue again using the first value. Preferably, the maximum boundaryvalue and minimum boundary value are both stored in the same repository314 of boundary values 210. In addition, the maximum boundary value andminimum boundary value are both referenced using the first value eitheras a direct index or to derive an index into the repository 314. As withthe maximum boundary value, the minimum boundary value is defined forthe function over a domain of the first argument.

The maximum boundary value defines an upper bound. If the second valueis greater than this upper bound the math function result will beoutside the range of computable results. The minimum boundary valuedefines an lower bound. If the second value is less than this lowerbound the function result is also outside the range of computableresults.

Accordingly, the comparison module 312 determines 608 determines whethersecond value satisfies the maximum boundary value and the minimumboundary value. If the second value is between the maximum boundaryvalue and the minimum boundary value, the math function result will beinside the range of computable results.

As described in more detail in relation to FIG. 5, if the math functionresult will be inside the range of computable results, the functionresult is similarly computed 610. If not, an error condition issimilarly signaled 612.

FIG. 7A illustrates a representative example of a table 700 illustratingone embodiment of a repository 314 of boundary values 210. In view ofthe description provided above, those of skill in the art will readilyrecognize that efficiencies for speed, reliability, and storage spacecan be made depending on the design of the repository 314, the functioninvolved, and the numeric representation used for the argument valuesand function result. FIGS. 7A-7C illustrate where a few of the manytradeoffs may be made to optimize certain embodiments for a particularuse or need.

For example in FIG. 7A, suppose the function is the power function,f(x,y)=x̂y. Further suppose, that x and y are integers represented in aprocessing system by 32-bit binary values. In addition, the powerfunction may be configured to perform validity tests on the argument forspecial values such as x or y equal to zero. Other special cases forwhich the result is limited by the use of integers include x=±1, y beinga negative value, and the like. As mentioned above, the power functionitself may be programmed to test and respond to these special cases.Positive values for y>1 and x≠1, 0, or −1 incur such an overhead thatfunction range test module 208 may be used to optimally determinewhether the result is computable prior to attempting to compute theresult.

Consequently, the repository 314 of boundary values 210 for this examplemay be organized as set forth in table 700. The table 700 includes twocolumns, one for y values, and one for maximum x values. Preferably, thenumber of columns corresponds to the number of arguments for thefunction. Those of skill in the art will recognize that use of y valuesand maximum x values is an implementation design decision. A similartable may be used in which one column is x values and the other columnis maximum y values. Similarly, whether maximum values or minimum valuesare used depends on the type of function and the representation for thearguments and result.

The table 700 is preferably predefined such that the data values of thetable 700 may be readily stored in high-speed and compact memory 202(See FIG. 2) such as a cache. Values in the “Exponent y” column maycomprise a sequential listing of y values other than the special casesdiscussed above. In FIG. 7A, the y values begin at 2 and end at 30.

As discussed above, one of the function arguments may be used as anindex into the table 700. In addition, the table may comprise a finitenumber of entries. In certain embodiments, depending on the function,values of y not found within the y column may be known to produceincomputable results regardless of the value of x. Consequently, if agiven y value is not within the table 700, the function range testmodule 208 may report an error condition.

The maximum x values are predefined using an inverse of the function andthe value y of the row. In this example, because the result is stored ina memory data structure of a 32-bit binary value, the upper limit onrepresentable numbers for the processing system is known. In thisexample, presuming 31 bits of binary data and a single sign bit, themaximum value the 32-bit result can hold is 2,147,483,647. Each maximumx value is determined by taking the y-th root of the maximum number thatthe 32-bit result can hold, 2,147,483,647, and truncating any fractionalpart of the square root to obtain the required maximum x value.

The table 700 illustrates that as y increases the maximum value for xrapidly decreases. If y is greater than 30 and x is any positive valuebesides 1, the result is greater than the value the 32-bit result canhold. The value is outside the range of computable results 114. Anoverflow condition would occur. Similarly, if y is 18 and x is a valuegreater than 3 an overflow condition would occur.

By quickly looking a y value up in the table 700, the function rangetest module 208 rapidly determines whether the x value is within theboundary value, maximum x. If not, evaluation of the function is abortedbefore computing resources are wasted. In addition, the function rangetest module 208 operates very rapidly such that the delay in evaluatinga function having valid arguments is minimized.

The table 700 also illustrates how the size and numeric representationfor the arguments and result can affect the range of computable results114. The maximum x values defined depend in part on the fact that thefunction and/or processing system is designed to handle strictlyintegers. Those of skill in the art will recognize that the table 700may be revised for functions that accept all floating point argumentsand produce a floating point result or that handle a mixture of floatingpoint and integers values.

FIG. 7B illustrates a representative example of a data structure used toorganize a memory location used to store atomic values used in theevaluation of the mathematical function. Typically, as in the exampleabove, the hardware and software of the processing system are designedto represent numbers using a certain size data structure, a memorylocation. The memory location may comprise RAM, cache, or a register.The size may be determined by the size of internal communication busesand internal communication protocols. Most processing systems representnumbers using a standard size 32-bit word 702. Data within the word 702be represented differently depending on the numeric representation usedby the processing system.

Typically, in a signed magnitude representation, the word 702 comprises31 data bits 704 and one sign bit 706. Alternatively, in atwo's-complement representation, a sign bit is still used but negativevalues are represented by the one's complement of the data bits 704 plusone. In yet another alternative, data in the word 702 may be representedusing the offset binary representation. Those of skill in the art willreadily recognize that the type of representation used by a processingsystem to represent the atomic values used in the math function affectsthe range of the computable results. If the one representation allowsfor a larger value to be stored and represented, the range of computableresults 114 is similarly affected. The converse is also true.Consequently, different manners for representing the values may affectwhat values are included in the repository 314 and/or whether additionspecial tests are included for special values of arguments.

Furthermore, if the processing system executing the function uses largerwords 702, the maximum and minimum representable values also increase.For example the word 702 may comprise sixty-four bits. Alternatively, incertain processing systems the word may comprise sixteen bits.Consequently, the size of the word 702 used to represent atomic values(single independently represented values) affects the scope of the rangeof computable results 114.

FIG. 7C illustrates a representative example of a table 708 illustratingone embodiment of a repository 314 of boundary values 210 in which theresult and arguments are real numbers. The table 708 includes an indexcolumn 710, a y column 712, a maximum x column 714, and a minimum xcolumn 716. In this example, the maximum x column 714 and minimum xcolumn 716 represent respectively a maximum boundary value and a minimumboundary value. The index values 710 are derived by subtracting asuitable base value (in this example, 1.00) from the y argument andmultiplying the result by the inverse (in this example, 4) of thedesired granularity (in this example, 0.25). This technique providesefficient access to the desired boundary values.

One embodiment operates using the table 708 as described above. If afloating point x value falls within the values for the maximum x column714 and minimum x column 716 for a given y value, the function willproduce a result within the range of computable results 114. In thisexample, again suppose the function is the power function f(x,y)=x̂y andthat x, y, and the result can be floating point or non-integer values.Because floating point values can be very small, an almost infinitenumber of possible values exist for the value of y. Consequently, thenumber of rows in the table 708 could be very large. Consequently,depending on the expected frequency that certain values of y will beprovided as arguments and the type of function, the number of entries orrows in the table 708 may be set to a finite number. In this manner, thesize of the table 708 can be kept minimal such that the benefits ofusing the table are not outweighed by space or retrieval delayrequirements.

To reference the table 708, the lookup module 310 preferably uses anindex or key using techniques similar to those described above.Typically, the argument value is used directly or as a basis to derivethe index. Consequently, how consecutive values for the argument valueare selected for entries in the table 708 affects the granularity fortesting certain values of the argument value.

In table 708, suppose that rows for successive y values are used inincrements of one-fourth (0.25). Further suppose that the functionaccepts any floating point value for the y value. The y values suppliedto the function are not limited to values that exactly match theselected increments of y values 712 in the table 708. In certainembodiments employing the table 708, a fast, simple rounding functionsuch as the one described above may be applied to the y value to derivethe index. In this manner, various floating point values of y can betested and the ranges for the maximum x 714 and minimum x 716 moreaccurately define the range of computable results 114.

FIG. 8 illustrates a graph 800 indicating the relationship of a firstargument to a second argument in defining the range of computableresults 114 for a given function f(x,y). The graph 800 includes a y-axis802 that represents values of y and an x-axis 804 that represents valuesof x. The curve 806 illustrates the boundary between a region 808 ofcomputable results and a region 810 of non-computable results for ageneric function f(x,y).

The boundary values 210 stored in the repository 314 facilitateidentifying whether a result will fall above or below the curve 806 fora given first argument value. Those of skill in the art will recognizethat depending on how y values are selected for entries in therepository 314, the curve may be more accurately approximated.Consequently, certain embodiments more accurately determine whether acomputable result is possible. However, those of skill in the art willalso recognize the tradeoff between closely approximating this curve 806and the overhead required to store and reference a larger repository314. As the curve is more closely approximated, the number of entries inthe repository 314 increases.

If the indexed function argument has almost an infinite number ofpossible values, those implementing a certain embodiment can determinehow the indexed function argument value is to be rounded, up or down, toderive an index for the desired boundary values. In FIG. 8, if theindexed function argument is y, rounding up may involve applying theceiling of y, rounding down may comprise taking the floor of y. Theseceiling and floor operations can create index values of any desiredgranularity, depending on the implementation tradeoffs described above.Those of skill in the art will recognize that the granularity of theindex values will be determined in part by the behavior of themathematical function in various argument ranges.

FIG. 8 illustrates certain tradeoffs in choosing to round up or rounddown. If rounding down to Floor(y) is selected, certain apparently validvalues of x less than the “Round Down Boundary” value may be allowed toproceed to evaluation of the function even though there is a chance thatthe x value will cause the result to fall in region 810, above thecurve. However, y and x values within the shaded Area A are alsopermitted for use in the function and valid computable results arecomputed.

Alternatively, if rounding up to Ceiling(y) is selected, certain valuesof x greater than the “Round Up Boundary” value are not allowed toproceed to evaluation of the function even though there is a chance thatthe y value will cause the result to fall within the shaded Area A,below the curve. Thus, some values of y and x that lead to validcomputable results could be excluded as invalid. Those of skill in theart will readily recognize the benefits and costs of making thesetradeoffs.

Advantageously, various embodiments of the present invention provide forefficient and reliable computation of results for mathematicalfunctions. Certain embodiments accurately and quickly test a pluralityof math function arguments to determine whether present argument valuesproduce a result within the range of computable results. Certainembodiments impose minimal overhead in evaluating math functions andsaves considerable computing resources that otherwise would be wastedevaluating a function for which the plurality of arguments would producean incomputable result.

The embodiments of the present invention may be embodied in otherspecific forms without departing from its spirit or essentialcharacteristics. The described embodiments are to be considered in allrespects only as illustrative and not restrictive. The scope ofdifferent embodiments of the invention is, therefore, indicated by theappended claims rather than by the foregoing description. All changeswhich come within the meaning and range of equivalency of the claims areto be embraced within their scope.

1. A method for efficient computation of results for mathematicalfunctions, the method comprising: receiving a mathematical functioncall, the call comprising a plurality of arguments for which a range ofcomputable results for the mathematical function of the function callvaries with respect to the values for the arguments; determining whetherexecuting the mathematical function using the plurality of argumentswill produce a result within the range of computable results; andaborting the mathematical function call prior to initiating execution ofthe mathematical function in response to determining that the values forthe plurality of arguments produce a result outside the range ofcomputable results.
 2. The method of claim 1, wherein the plurality ofarguments comprise a first argument value and a second argument valueand the range of computable results defines at least one boundary valuefor the second argument value, the boundary value varying as the firstargument value varies.
 3. The method of claim 1, further comprising,reading a first value associated with a first argument of themathematical function and a second value associated with a secondargument; retrieving a boundary value from a repository of predefinedboundary values defined for the mathematical function over a domain ofthe first argument, the boundary value retrieved using the first value;determining whether the second value satisfies the boundary value. 4.The method of claim 3, wherein the repository is a table and the firstvalue comprises an index into the table of boundary values.
 5. Themethod of claim 3, wherein the boundary value comprises a maximumboundary value and the repository of boundary values comprises themaximum boundary value and a minimum boundary value, wherein the methodretrieves the minimum boundary value from the repository of boundaryvalues defined for the mathematical function over a domain of the firstargument, the minimum boundary value retrieved using the first value andthe method determines whether the second value satisfies the maximumboundary value and the minimum boundary value.
 6. The method of claim 3,wherein the repository of predefined boundary values comprises a finitenumber of entries for a first argument having an infinite number ofpossible values, the finite number selected to minimize the size of therepository of predefined boundary values in relation to anticipatedvalues for the first value.
 7. The method of claim 1, wherein the rangeof computable results is defined based on the size of a memory locationthat stores atomic values during evaluation of the mathematicalfunction.
 8. The method of claim 1, wherein the range of computableresults is defined based on a numeric representation used to storeatomic values used to evaluate the mathematical function.
 9. The methodof claim 1, wherein the range of computable results is defined accordingto a numeric type defined for one or more of the plurality of arguments,the numeric type selected from the group consisting of an integer type,a non-integer type, and a floating point type.
 10. The method of claim1, further comprising signaling an error condition in response todetermining that the plurality of arguments produce a result outside therange of computable results.
 11. A method for efficient computation ofresults for mathematical functions, the method comprising: receiving amathematical function call, the call comprising a plurality of argumentsfor which a range of computable results for the mathematical function ofthe function call varies with respect to the values for the arguments;determining whether executing the mathematical function using theplurality of arguments will produce a result within the range ofcomputable results; aborting the mathematical function call prior toinitiating execution of the mathematical function in response todetermining that the values for the plurality of arguments produce aresult outside the range of computable results; wherein the plurality ofarguments comprise a first argument value and a second argument valueand the range of computable results defines at least one boundary valuefor the second argument value, the boundary value varying as the firstargument value varies; and reading a first value associated with a firstargument of the mathematical function and a second value associated witha second argument; retrieving a boundary value from a repository ofpredefined boundary values defined for the mathematical function over adomain of the first argument, the boundary value retrieved using thefirst value; and determining whether the second value satisfies theboundary value.
 12. The method of claim 11, wherein the repository is atable and the first value comprises an index into the table of boundaryvalues.
 13. The method of claim 11, wherein the boundary value comprisesa maximum boundary value and the repository of boundary values comprisesthe maximum boundary value and a minimum boundary value, wherein themethod retrieves the minimum boundary value from the repository ofboundary values defined for the mathematical function over a domain ofthe first argument, the minimum boundary value retrieved using the firstvalue and the method determines whether the second value satisfies themaximum boundary value and the minimum boundary value.
 14. The method ofclaim 11, wherein the repository of predefined boundary values comprisesa finite number of entries for a first argument having an infinitenumber of possible values, the finite number selected to minimize thesize of the repository of predefined boundary values in relation toanticipated values for the first value.
 15. The method of claim 11,wherein the range of computable results is defined based on the size ofa memory location that stores atomic values during evaluation of themathematical function.
 16. The method of claim 11, wherein the range ofcomputable results is defined based on a numeric representation used tostore atomic values used to evaluate the mathematical function.
 17. Themethod of claim 11, wherein the range of computable results is definedaccording to a numeric type defined for one or more of the plurality ofarguments, the numeric type selected from the group consisting of aninteger type, a non-integer type, and a floating point type.
 18. Themethod of claim 11, further comprising signaling an error condition inresponse to determining that the plurality of arguments produce a resultoutside the range of computable results.